package mediadisplay.timeline.controls 
{
	import flash.display.GradientType;
	import flash.display.SpreadMethod;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.filters.GlowFilter;
	import flash.geom.Matrix;
	/**
	 * ...
	 * @author Anders Figenschow
	 */
	public class ButtonBase extends Sprite
	{
		
		public function ButtonBase() 
		{
			if (stage) init();
			else addEventListener(Event.ADDED_TO_STAGE, init);
		}
		
		private function init(e:Event = null):void 
		{
			removeEventListener(Event.ADDED_TO_STAGE, init);
			var fType:String = GradientType.LINEAR;
			var colors:Array = [ 0xffffff, 0 ];
			var alphas:Array = [ 1, 1 ];
			var ratios:Array = [ 0, 255 ];
			var matr:Matrix = new Matrix();
			matr.createGradientBox( 60, 10, 0, 0, 0 );
			matr.rotate(Math.PI/2);
			var sprMethod:String = SpreadMethod.PAD;
			
			graphics.clear();
			graphics.lineStyle(1, 0x666666, 1, true);
			graphics.beginGradientFill( fType, colors, alphas, ratios, matr, sprMethod );
			graphics.drawRoundRect(0, 0, 45, 30, 10, 10);
			graphics.endFill();	
			
			buttonMode = true;
			
			addEventListener(MouseEvent.MOUSE_OUT, mouseOutHandler);
			addEventListener(MouseEvent.MOUSE_OVER, mouseOverHandler);
			
			alpha = 0.8;
		}
		
		private function mouseOverHandler(e:MouseEvent):void 
		{
			alpha = 1;
			filters = [new GlowFilter(0xffffff, 0.4, 5, 5)];
		}
		public function changeColor(color:uint):void {
			var fType:String = GradientType.LINEAR;
			var colors:Array = [ color, 0 ];
			var alphas:Array = [ 1, 1 ];
			var ratios:Array = [ 0, 255 ];
			var matr:Matrix = new Matrix();
			matr.createGradientBox( 60, 10, 0, 0, 0 );
			matr.rotate(Math.PI/2);
			var sprMethod:String = SpreadMethod.PAD;
			
			graphics.clear();
			graphics.lineStyle(1, 0x666666, 1, true);
			graphics.beginGradientFill( fType, colors, alphas, ratios, matr, sprMethod );
			graphics.drawRoundRect(0, 0, 45, 30, 10, 10);
			graphics.endFill();	
			
		}
		private function mouseOutHandler(e:MouseEvent):void 
		{
			alpha = 0.8;
			filters = [];
		}
		
	}

}